<!--
* description: 时间选择器
* author: dxuem
* createdDate: 2019-12-11
-->
<template>
  <el-col :span="span" id="crmTimePicker">
    <lableName
      :validrule="validrule"
      :curLabelName="curLabelName"
      :isShowLabel="isShowLabel"
      :isRequire="isRequire"
    ></lableName>
    <el-time-select
      v-model="modelCode"
      placeholder="请选择时间"
      :picker-options="pickerOptions"
      @change="sendCode"
      clearable
      :disabled="disabled"
    ></el-time-select>
    <validateFormate :curLabelName="curLabelName" :validrule="validrule"></validateFormate>
  </el-col>
</template>

<script>
import { inputMixins } from "@/components/mixins/inputMixins";
import { type } from "os";
// import lableName from "@/components/lableName";
// import validateFormate from "@/components/validateFormate";
export default {
  name: "crmTimePicker",
  mixins: [inputMixins],
  components: {
    lableName: () => import("@/components/lableName"), //标题溢出样式组件
    validateFormate: () => import("@/components/validateFormate") //校验提示样式组件
  },
  props: {
    span: {
      type: Number,
      default: function() {
        return 6;
      }
    }
    // start:{type:String,default:'8:30'}
  },
  data() {
    return {
      pickerOptions: {
        start: "08:30",
        step: "00:15",
        end: "18:30"
      }
    };
  },
//   watch: {
//     modelCode(val) {
//       debugger;
//       this.$emit("emitCode", val);
//       let str = this.codeField;
//       this.$parent.$parent.$parent.formField[str] = val;
//     }
//   },
  watch: {
    modelCode(val) {
      let str = this.codeField;
      if (str) {
        this.$crmcf.__getParent(this, "formField", function(formField) {
          if (val != null) {
            formField[str] = val;
          }else{
            formField[str] = "";
          }
        });
      }
      this.$emit("emitCode", val);
    }
  },
  created() {
    const that = this;
    that.pickerOptions.disabledDate = function(time) {
      if (that.dateOptionsType) {
        switch (that.dateOptionsType) {
          // 禁用当前日期之后的日期（不包括当前日期）
          case "1":
            return time.getTime() > Date.now();
          // 禁用当前日期之前的日期（包括当前日期）
          case "2":
            return time.getTime() < Date.now();
        }
      }
      return false;
    };
  },
  methods: {
    getData(val) {
      this.pickerOptions.start = val;
    }
  }
};
</script>
